package com.cat.dataStructure;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/zero-array-transformation-i/
 * @create 2025/8/23 15:50
 * @since JDK17
 */

public class Solution47 {
    public boolean isZeroArray(int[] nums, int[][] queries) {
        int n = nums.length, m = queries.length, sum = 0;
        int[] diff = new int[n + 1];
        for (int i = 0, t; i < m; i++) {
            diff[queries[i][0]]--;
            diff[queries[i][1] + 1]++;
        }
        for (int i = 0; i < n; i++) {
            sum += diff[i];
            if (sum + nums[i] > 0) {
                return false;
            }
        }

        return true;
    }
}
